


//
//  MemberDayView.m
//  ZQLearn
//
//  Created by macfeel on 2019/5/7.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "MemberDayView.h"
@interface MemberDayView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)UICollectionView *iconCollectionView;

@property(nonatomic,strong)NSArray *imageViewArray;

@end

#define iconCellID @"mday"

@implementation MemberDayView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        //        [self makeUI];
//        self.backgroundColor = kMagentaColor;
        
    }
    
    return self;
    
}

-(void)setDataArray:(NSArray *)dataArray{
    
//    [SVProgressHUD show];
    
    _dataArray = dataArray;
    
    [self makeUI];
    
    _iconCollectionView.dataSource = self;
    _iconCollectionView.delegate = self;
    
    [self.iconCollectionView reloadData];
    
//    [SVProgressHUD dismiss];
    
}

-(void)setTitleArray:(NSArray *)titleArray{
    _titleArray = titleArray;
    [self makeUI];
    _iconCollectionView.dataSource = self;
}

//-(void)setIconArray:(NSArray *)iconArray{
//
//    _iconArray = iconArray;
//
//    //数据接收完成后再开始布局
//
//    [self makeUI];
//
//    _iconCollectionView.dataSource = self;
//
//}

-(void)makeUI{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置itemSize
    ////这个属性决定了可以急等分屏幕并决定 是否滚动
    layout.itemSize = CGSizeMake(ScreenWidth/3-20,130.f);
    
    ///横向的  ******** 这个是关键中的关键   如果要横向布局，这个是必须的
    ////默认是纵向的
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    //这三个属性至关重要  vip  ************一旦方向是UICollectionViewScrollDirectionHorizontal，那么minimumLineSpacing这个属性就是视觉上的纵向间距
    layout.minimumLineSpacing = 15;
    layout.minimumInteritemSpacing = 20;
    layout.sectionInset = UIEdgeInsetsMake(25, 15, 2, 0);
    
    //2.初始化collectionView
    _iconCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth,self.frame.size.height) collectionViewLayout:layout];
    _iconCollectionView.bounces = YES;
    _iconCollectionView.delegate = self;
    _iconCollectionView.showsHorizontalScrollIndicator = false;
    _iconCollectionView.backgroundColor = kWhiteColor;
    
    
    ///注意是xib 还是手写的  如果是xib  而用了class那么cell 是创建不出来的
//    [_iconCollectionView registerClass:[MemberDayCollectionCell class] forCellWithReuseIdentifier:iconCellID];
    [_iconCollectionView registerNib:[UINib nibWithNibName:@"MemberDayCollectionCell" bundle:nil] forCellWithReuseIdentifier:iconCellID];
    [self addSubview:_iconCollectionView];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
//    return _titleArray.count;
    return self.dataArray.count;
//    return 3;
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CommonModel *model = self.dataArray[indexPath.row];
    
    MemberDayCollectionCell *cell = (MemberDayCollectionCell*)[collectionView dequeueReusableCellWithReuseIdentifier:iconCellID forIndexPath:indexPath];
    cell.layer.borderColor = kLightGrayColor.CGColor;
    cell.layer.borderWidth = 1.f;
    cell.layer.cornerRadius = 10.f;
    cell.layer.masksToBounds = YES;
//    cell.topLab.text = self.titleArray[indexPath.row];
    cell.topLab.text = [NSString stringWithFormat:@"%@天",model.vipDays];
    cell.midLab.text = [NSString stringWithFormat:@"￥%@",model.preferentialMoney];
//    cell.bottomLab.text = [NSString stringWithFormat:@"原价:%@",model.orderMoney];
    NSString *tempText = [NSString stringWithFormat:@"原价:%@",model.orderMoney];
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:tempText attributes:attribtDic];
    cell.bottomLab.attributedText = attribtStr;
    
//    if (indexPath.row==0) {
//        cell.midLab.text = @"￥29";
//        cell.bottomLab.text = @"原价30";
//    }else if (indexPath.row==1){
//        cell.midLab.text = @"￥86";
//         cell.bottomLab.text = @"原价90";
//    }else{
//        cell.midLab.text = @"￥300";
//         cell.bottomLab.text = @"原价360";
//    }
    
//    cell.iconImage.image = WDImgName(self.iconArray[indexPath.row]);
//    cell.nameLabel.text = self.titleArray[indexPath.row];
    
    //    if (_iconArray.count > indexPath.row) {
    //        WDFourIconModel *model = _iconArray[indexPath.row];
    //        [cell configData:model];
    //    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
//    YYLog(@"jjj下标：%ld",indexPath.row);
    YYLog(@"%ld",indexPath.row);
    CommonModel *model = self.dataArray[indexPath.row];
    if (_block) {
        _block(indexPath.row,model);
    }
    //存储当前下标，然后全局存储，立即开通时进行不同的传值
    //    NFourIconModel *model = self.iconArray[indexPath.row];
//    if (_indexBlock) {
//
//        NSLog(@"%ld",(long)indexPath.row);
//        _indexBlock(indexPath.row);
//
//    }
    
}

@end
